"""
文件名: OrderInterface

"""
from interface.member import MemberInterface
from utils.send_method import SendMethod


class OrderInterface:
    def __init__(self, headers):
        self.url = "http://47.108.206.100:8085"
        self.headers = headers

    def confirm_order(self,cart_id):
        """
        确认订单
        :return:
        """
        method = 'post'
        url = self.url + '/order/generateConfirmOrder'
        payload = [cart_id]
        return SendMethod.send_method(method=method, url=url, json=payload, headers=self.headers)

    def generate_order(self,cart_id):
        """
        生成订单,本次项目中没有优惠券和积分,只需要收货地址id和支付方式即可
        :return:
        """
        method = 'post'
        url = self.url + '/order/generateOrder'
        payload = {
            "cartIds": [
                cart_id
            ],
            "memberReceiveAddressId": 3046,  # 收货地址id
            "payType": 2,  # 支付方式,0: 未支付;1: 支付宝,;2: 微信
        }

        return SendMethod.send_method(method=method, url=url, json=payload, headers=self.headers)

    def pay_success(self, order_id):
        """
        支付成功回调
        :return:
        """
        method = 'post'
        url = self.url + '/order/paySuccess'
        payload = {"orderId": order_id,"payType":2}
        return SendMethod.send_method(method=method, url=url, data=payload, headers=self.headers)


if __name__ == '__main__':
    body = {
        "username": "jack",
        "password": "123456"
    }
    headers = MemberInterface().get_token(body)
    order = OrderInterface(headers)
    # print(order.confirm_order(22))  # 调用确认订单接口
    # print(order.generate_order(22))  # 调用生成订单接口
    print(order.pay_success(31))  # 调用支付成功回调接口
